package com.ruoyi.syf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.syf.common.constant.Check;
import com.ruoyi.syf.domain.RiskCheckDanger;
import com.ruoyi.syf.mapper.RiskCheckDangerMapper;
import com.ruoyi.syf.service.IRiskCheckDangerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 排查隐患Service业务层处理
 *
 * @author yr
 * @date 2024-08-03
 */
@Service
public class RiskCheckDangerServiceImpl extends ServiceImpl<RiskCheckDangerMapper,RiskCheckDanger> implements IRiskCheckDangerService {
    @Autowired
    private RiskCheckDangerMapper riskCheckDangerMapper;

    @Override
    public RiskCheckDanger getByRecordId(Long recordId) {
        LambdaQueryWrapper<RiskCheckDanger> lqw = new LambdaQueryWrapper<>();
        lqw.eq(RiskCheckDanger::getRecordId, recordId)
                .eq(RiskCheckDanger::getDelFlag, "0");
        RiskCheckDanger danger = riskCheckDangerMapper.selectOne(lqw);
        if (danger == null){
            throw new NullPointerException("隐患记录不存在");
        }
        return danger;
    }

    @Override
    public boolean mySave(RiskCheckDanger riskCheckDanger,Long recordId) {
        riskCheckDanger.setRecordId(recordId);
        riskCheckDanger.setDangerStatus(Check.CheckInfo.D_TO_CONFIRM.getCode());
        return save(riskCheckDanger);
    }

    /**
     * 批量删除排查隐患
     *
     * @param ids 需要删除的排查隐患主键
     * @return 结果
     */
    @Override
    public int deleteRiskCheckDangerByIds(Long[] ids) {
        return riskCheckDangerMapper.deleteRiskCheckDangerByIds(ids);
    }

    /**
     * 删除排查隐患信息
     *
     * @param id 排查隐患主键
     * @return 结果
     */
    @Override
    public int deleteRiskCheckDangerById(Long id) {
        return riskCheckDangerMapper.deleteRiskCheckDangerById(id);
    }
}
